package cn.crex1.kafka.producer;

import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class KafkaProducer {

    @Autowired
    KafkaTemplate<String,String> kafkaTemplate;

    public void add1(){
        kafkaTemplate.send(new ProducerRecord<>("topic1", "foo1"));
        kafkaTemplate.flush();
    }
    public void add2(){
        kafkaTemplate.send(new ProducerRecord<>("topic2", "还可以配置具有明显主题和分区（以及可选地，它们的初始偏移）的POJO侦听器："));
        kafkaTemplate.flush();
    }
}
